package com.itheima.wemedia.controller;

import com.itheima.common.enums.HttpCodeEnum;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.common.vo.ResultVo;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WmUserFaginController {

    //注入service对象
    @Autowired
    private WmUserService wmUserService;
    /**
     * 远程调用查询自媒体数据库
     * @param apiUserId 接收远程调用的id
     * @return 返回查询到的数据给远程调用的方法
     */
    @GetMapping("/api/wmUser/{apiUserId}")
    public ResultVo<WmUser> findById(@PathVariable Long apiUserId){
        WmUser wmUser = wmUserService.findUserById(apiUserId);
        return ResultVo.ok(wmUser);
    }

    /**
     * 远程调用添加wmUser
     * @param wmUser 接收远程调用返回的参数
     * @return 返回添加是否成功的数据
     */
    @PostMapping("/api/wmUser/add")
    public ResultVo<com.itheima.wemedia.pojo.WmUser> addWmUser(@RequestBody com.itheima.wemedia.pojo.WmUser wmUser){
        if (wmUserService.save(wmUser)) {
            return ResultVo.ok();
        }
        return ResultVo.error(HttpCodeEnum.SERVER_ERROR);
    }
}
